package cn.hr.service.impl;

import cn.hr.dao.mapper.SysRoleMapper;
import cn.hr.pojo.SysRole;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by MO on 2018/12/25.
 */
@CacheConfig(cacheNames = "role")
@Scope("prototype")
@Service("roleService")
public class SysRoleService {
    @Resource
    private SysRoleMapper roleMapper;

    @Cacheable(keyGenerator = "keyGenerator")
    public SysRole findById(int id) throws Exception {
        return roleMapper.findById(id);
    }

    @Cacheable(keyGenerator = "keyGenerator")
    public SysRole findByName(String name) throws Exception {
        return roleMapper.findByName(name);
    }

    /**
     * 查询所有的角色
     * @return
     * @throws Exception
     */
    @Cacheable(keyGenerator = "keyGenerator")
    public List<SysRole> findAll() throws Exception{
        return roleMapper.findAll();
    }
}
